package com.zeropoint.demo.pojo;


import com.zeropoint.demo.pojo.vo.OperatingIncome;
import com.zeropoint.demo.pojo.vo.PropertyIncome;
import com.zeropoint.demo.pojo.vo.TransferIncome;
import com.zeropoint.demo.pojo.vo.WageIncome;
import lombok.ToString;

/**
 * 家庭支出指标标准化
 */
@ToString
public class FamilyOutcomeStandardized {

    //数据汇总
    //总人口
    public int totalPopulation;
    //主要消费支出项目
    public String[] consumption;
    //家庭每月日常生活消费支出
    public int dailyLivingConsumption;
    //家庭每月通信费用
    public double communication;
    //每月社会养老保险费用
    public double endowmentInsurance;

    //数据整理
    //人均净收入
    public double perCapitaNetIncome;
    //生活保障支出
    public double livingSecurityExpenditure;
    //家庭日常消费支出
    public double dailyConsumptionExpenditure;
    //家庭必要刚性支出
    public double necessaryRigidExpenditure;
    //社会交往支出
    public double socialExpenditure;
    //突发性支出
    public double suddenExpenditure;
    //该县（市、区）人均可支配收入
    public double perDisposableIncome;

    //计算结果
    //家庭人均日常通讯费用赋值
    public double dailyCommunicationAssignment;
    //家庭每月社会养老保险费用
    public double endowmentInsuranceAssignment;
    //人均消费支出赋值
    public double consumptionExpenditureAssignment;
    //人均必要刚性支出赋值
    public double necessaryRigidAssignment;
    //社会交往支出赋值
    public double socialInteractionAssignment;
    //突发性支出赋值
    public double suddenAssignment;
    //人均净收入赋值
    public double perNetIncomeAssignment;
    //人均生活保障赋值
    public double perLifeSecurityAssignment;

    //totalRevenue为收入标准化表中的收入总额
    public FamilyOutcomeStandardized(FormFour four, FormTwo two,Questionnaire_info info, double totalRevenue){

        totalPopulation = HumanResourceStandardized.totalPopulation;

        consumption = four.dailyConsumption.spendProject;

        if("30%".equals(four.dailyConsumption.foodExpenditurePoint)){
            dailyLivingConsumption = 1;
        }else if("30%-40%".equals(four.dailyConsumption.foodExpenditurePoint) || "30%~40%".equals(four.dailyConsumption.foodExpenditurePoint)){
            dailyLivingConsumption = 2;
        }else if("40%-50%".equals(four.dailyConsumption.foodExpenditurePoint) || "40%~50%".equals(four.dailyConsumption.foodExpenditurePoint)){
            dailyLivingConsumption = 3;
        }else{
            dailyLivingConsumption = 4;
        }

        communication = two.mon_communication_fee;

        endowmentInsurance = four.dailyConsumption.endowmentInsuranceCost;

        dailyConsumptionExpenditure = four.dailyConsumption.endowmentInsuranceCost + four.dailyConsumption.rentalFee
                + two.mon_communication_fee + two.mon_electricity_fee;

        necessaryRigidExpenditure = four.necessaryExpenses.accommodation
                + four.necessaryExpenses.livingExpenses
                + four.necessaryExpenses.educationOutCome
                + four.necessaryExpenses.tuition
                + four.necessaryExpenses.bookMoney
                + four.necessaryExpenses.bigPersonMoney
                + four.necessaryExpenses.slowPersonMoney
                + four.necessaryExpenses.treatmentDisabledMoney
                + four.necessaryExpenses.employmentMoney;

        socialExpenditure = four.socialExpenditure.contactMoney;

        suddenExpenditure = four.suddenExpenditure.emergentEventMoney;

        livingSecurityExpenditure = dailyConsumptionExpenditure -  necessaryRigidExpenditure
                - socialExpenditure - suddenExpenditure;

        perCapitaNetIncome = (totalRevenue - (dailyConsumptionExpenditure + necessaryRigidExpenditure
                + socialExpenditure + suddenExpenditure))/totalPopulation;

        perDisposableIncome = info.village_disposable_income;

        //家庭人均日常通讯费用赋值
        if(communication/totalPopulation > 40){
            dailyCommunicationAssignment = 1;
        }else{
            dailyCommunicationAssignment = (communication/totalPopulation)/40;
        }

        //家庭每月社会养老保险费用
        if(endowmentInsurance <= 0){
            endowmentInsuranceAssignment = 0;
        }else if(endowmentInsurance <= 200){
            endowmentInsuranceAssignment = 0.2;
        }else if(endowmentInsurance <= 400){
            endowmentInsuranceAssignment = 0.4;
        }else if(endowmentInsurance <= 600){
            endowmentInsuranceAssignment = 0.6;
        }else if(endowmentInsurance <= 800){
            endowmentInsuranceAssignment = 0.8;
        }else {
            endowmentInsuranceAssignment = 1;
        }

        double d = (dailyConsumptionExpenditure + necessaryRigidExpenditure
                + socialExpenditure + suddenExpenditure)/totalPopulation;
        //人均消费支出赋值
        if(d <= perDisposableIncome){
            consumptionExpenditureAssignment = d/perDisposableIncome;
        }else {
            consumptionExpenditureAssignment = 1;
        }

        double d2 = necessaryRigidExpenditure/totalPopulation;
        if(d2 <= 20000){
            necessaryRigidAssignment = d2/20000;
        }else {
            necessaryRigidAssignment = 1;
        }

        if(socialExpenditure > 20000){
            socialInteractionAssignment = 1;
        }else {
            socialInteractionAssignment = socialExpenditure/20000;
        }

        if(suddenExpenditure > 20000){
            suddenAssignment = 1;
        }else {
            suddenAssignment = suddenExpenditure/20000;
        }


        if(perCapitaNetIncome <= 0){
            perNetIncomeAssignment = 0;
        }else if(perCapitaNetIncome <= 20000){
            perNetIncomeAssignment = perCapitaNetIncome/20000;
        }else {
            perNetIncomeAssignment = 1;
        }

        if(perCapitaNetIncome <= 0){
            perLifeSecurityAssignment = 0;
        }else if(perCapitaNetIncome <= perDisposableIncome){
            perLifeSecurityAssignment = perCapitaNetIncome/perDisposableIncome;
        }else {
            perLifeSecurityAssignment = 1;
        }

    }

    public static void main(String[] args) {
        //初始化表家庭支出指标标准化
        Questionnaire_info info = new Questionnaire_info();
        info.city_disposable_income = 22661;
        info.wage_income = 8684;
        info.operational_income = 6934;
        info.property_income = 90;
        info.transfer_income = 1115;
        info.minimum_living_level = 515;

        FormThree formThree = new FormThree();
        formThree.operatingIncome = new OperatingIncome();
        formThree.operatingIncome.selfEmployedOucome = 12000;
        formThree.wageIncome = new WageIncome();
        formThree.wageIncome.localFamlyIncome = 3000;
        formThree.propertyIncome = new PropertyIncome();
        formThree.transferIncome = new TransferIncome();
        formThree.transferIncome.livingAllowances = 5040;
        HumanResourceStandardized.totalPopulation = 4;
        //先建立表 家庭支出指标标准化
        FamilyIncomeStandardized i = new FamilyIncomeStandardized(info, formThree);

        FormFour four = new FormFour();
        four.dailyConsumption.spendProject = new String[]{"家庭日常消费支出", "子女教育"};
        four.dailyConsumption.foodExpenditurePoint = "30%-40%";
        FormTwo two = new FormTwo();
        two.mon_communication_fee = 200; //表有误
        four.dailyConsumption.endowmentInsuranceCost = 830;
        four.dailyConsumption.rentalFee = 1500;
        two.mon_electricity_fee = 300;

        four.necessaryExpenses.livingExpenses = 3000;
        four.necessaryExpenses.educationOutCome = 11000;
        four.necessaryExpenses.tuition = 8000;
        four.necessaryExpenses.slowHealthSpending = 120000;
        four.necessaryExpenses.slowPersonMoney = 20000;

        four.socialExpenditure.contactMoney = 1000;
        four.suddenExpenditure.emergentEventMoney = 0;

        FamilyOutcomeStandardized o = new FamilyOutcomeStandardized(four, two, info, i.totalRevenue);
        System.out.println(o);
    }
}
